package com.xcity.game.task.detector;

import com.alibaba.fastjson.JSONObject;
import com.xcity.db.entity.Employee;
import com.xcity.db.entity.Player;
import com.xcity.game.task.Task;
import com.xcity.game.task.TaskDetector;
import com.xcity.game.task.TaskDetectorLabel;

/**
 * <pre>
 * 培养员工(等级)
 * 1个参数:
 * 1.等级
 * </pre>
 * @author yang.li
 *
 */
@TaskDetectorLabel(TaskDetector.TRAIN_EMPLOYEE_LEVEL)
public class TrainEmployeeLevelTaskDetector implements TaskDetector {

	static final String KEY = String.valueOf(TRAIN_EMPLOYEE_LEVEL);
	
	@Override
	public boolean isFinish(Task task) {
		int n = task.getTemplate().getConditions()[0];
		return task.getArchive().getIntValue(KEY) >= n;
	}

	@Override
	public void onArchive(Task task, Object... vals) {
		// { 15: maxLvl }
		Employee e = (Employee) vals[1];
		JSONObject archive = task.getArchive();
		if (e.getLevel() > archive.getIntValue(KEY)) {
			archive.put(KEY, e.getLevel());
		}
	}

}
